﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class reset_ct_s : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        ctpDataContext db = new ctpDataContext();
        var data = from p in db.ct_s_profiles
                   orderby p.no
                   select p.no;

        foreach (var d in data.Distinct())
        {

            try
            {
                var data1 = from p in db.ct_s_profiles
                            where p.no == (int)d
                            orderby p.ver descending
                            select p;


                ct_s_profile newp = data1.First();

                newp.valid = true;

                Response.Write(d.ToString() + "<br>");
                Response.Write(newp.ver.ToString());
                Response.Write("<p>");




               // ct_s_profile newp = db.ct_s_profiles.Single(p => p.no == (int)d && p.valid == true);
            }
            catch (Exception e1)
            {
                Response.Write("err "+d.ToString() + "<br>");
                Response.Write("<p>");


                //var data1 = from q in db.ct_s_profiles
                //            where q.no == (int)d
                //            select q;

                //foreach (ct_s_profile sp in data1)
                //{
                //    Response.Write(sp.title.Trim() + "<br>");


                //}

                //Response.Write("<p>");


            }


        }

        db.SubmitChanges();


    }
}
